package cn.jiyun.controller;

import cn.jiyun.Service.Uservice;
import cn.jiyun.pojo.Day3;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("user")
public class UController {
    @Autowired
    private Uservice uservice;

    @RequestMapping("findAll")
    public Page findAll(@RequestParam(required = true,defaultValue = "1")Integer pageNum, @RequestBody Day3 day3){
        Page<Day3> page1=new Page<>(pageNum,3);
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.like(day3.getName()!=null,"name",day3.getName());
        queryWrapper.gt(day3.getAge()!=null,"age",day3.getAge());
//        LambdaQueryWrapper queryWrapper1=new LambdaQueryWrapper();
        Page<Day3> list=uservice.findAll(page1,queryWrapper );
        return list;

    }
    @RequestMapping("del")
    public void del(Integer id){
        uservice.del(id);

    }

    @RequestMapping("add")
    public void add(@RequestBody Day3 day3){
       if (day3.getId()==null){
           uservice.add(day3);
       }else {
           uservice.update(day3);
       }

    }

    @RequestMapping("hx")
    public Day3 hx(Integer id){
       Day3 day3= uservice.hx(id);
        return day3;
    }


}
